#
# 使用脚本达成类似pl/sql插件的exPaste功能
# 复制好需要排版的列，直接执行此脚本，排版好后的数据会自动进入系统粘贴板中
#
import pyperclip as pp


def reverse_replace(self, old, new, *max):
    count = len(self)
    if max and str(max[0]).isdigit():
        count = max[0]
    while count:
        index = self.rfind(old)
        if index >= 0:
            chunk = self.rpartition(old)
            self = chunk[0] + new + chunk[2]
        count -= 1
    return self


if __name__ == '__main__':

    with open('exPasteFile.txt', 'w') as fw:
        fw.write(pp.paste())

    with open("exPasteFile.txt", 'r') as f:
        exPasteStr = f.read()
        # 修改换行符
        exPasteStr = exPasteStr.replace("\n", "\',\'")
        # 修改头部
        exPasteStr = "('" + exPasteStr
        # 修改尾部
        exPasteStr = exPasteStr + "')"
        # 修改空数据
        exPasteStr = exPasteStr.replace(",\'\'", "")

    pp.copy(exPasteStr)

    print(exPasteStr)
    print("""
    ************* 已将修改后的数据放入粘贴板 ****************
    ************* 可以直接ctrl+v进行复制！ ****************
    """)


